package control;

import user.Menu;
import user.SystemMenu;
import utils.DBUtils;

import java.sql.ResultSet;
import java.util.Scanner;



public class GoodsFunction {
    Scanner input;
    public void runFunction(){
        Scanner scanner=new Scanner(System.in);
        try {
            Goods goods;
            String goodsId = "";//运行时输入
            do {
                menu.runmenu();
                String userChoice = scanner.next();
                switch (userChoice) {
                    case "a":
                        UserManagement();
                        break;
                    case "b":
                        GoodsManagement();

                        break;
                    case "c":
                        OrderManagement();
                        break;
                    case "d":
                        Statistics();
                        break;
                    case "e":
                        exit();
                        break;
                }
                System.out.println("按任意键继续..."); System.in.read();
            } while (true);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("系统出错了，请重试");
        }

    }
    public void UserManagement(){

    }//用户管理
    public static void GoodsManagement(){
        GoodsController nn=new GoodsController();
        nn.startSystem();
    }//商品管理
    public void OrderManagement(){
        String sql = "select * from tb_user";
        try {
            ResultSet resultSet = DBUtils.executeQuery(sql, null);
            while (resultSet.next()) {
                String Accountid = resultSet.getString("Accountid");
                String name = resultSet.getString("name");
                String good = resultSet.getString("good");
                int number = resultSet.getInt("number");
                System.out.println("Accountid: " + Accountid + ", Name: " + name + ", good: " + good + ", number: " + number );
            } }catch(Exception e){
            throw new RuntimeException(e);
        }
    }//订单管理
    public void  Statistics(){
        String sql = "select sum(total) from tb_user";
        try {
            ResultSet resultSet = DBUtils.executeQuery(sql, null);
            while (resultSet.next()) {
                double totalmoney = resultSet.getDouble("sum(total)");
                System.out.println("总销售金额: " + totalmoney);
            } }catch(Exception e){
            throw new RuntimeException(e);
        }

    }//统计
    public void  exit() {
        System.out.print("是否真的要退出系统？（Y|N）:");
        String userInput = input.next();
        if (userInput.equalsIgnoreCase("y")) {
            System.exit(0);
        }
    }

}

